from api import DnsPodApi, get_internet_ip
from time import sleep

dns_pod = DnsPodApi("https://dnsapi.cn")

# 创建记录
sub_domain = "demo3"  # 记录前缀
rsp_obj = dns_pod.create_records(value="127.0.0.1", sub_domain=sub_domain)
assert rsp_obj.response_status_code == "1"
# 获取外网IP
internet_ip = get_internet_ip()
sleep(10)
# 更新记录,将记录更新为外网IP
rsp = dns_pod.update_records(record_id=rsp_obj.response_record_id, new_value=internet_ip, sub_domain=sub_domain)
assert rsp.response_status_code == "1"
# 查询记录,验证是否更新成功
rsp = dns_pod.get_records_list(sub_domain=sub_domain)
new_record_value = rsp.response_latest_record_value_in_list
sleep(10)
assert rsp.response_status_code == "1"
assert new_record_value == internet_ip
# 删除记录
rsp = dns_pod.delete_records(record_id=rsp_obj.response_record_id)
assert rsp.response_status_code == "1"
